package com.atguigu.day211105.work;

import java.util.Scanner;

public class Test {
    public static void main(String[] args) {
        BankCard b = new BankCard(10086,10000);
        CreditCard c= new CreditCard(10010,5000,3000);
        BankCard[] card=new BankCard[2];
        card[0]=b;
        card[1]=c;

        Scanner input = new Scanner(System.in);

        for (int i = 0; i < card.length; i++) {
            System.out.println(card[i].getInfo());
        }

        System.out.println("输入取款金额:");
        double out = input.nextDouble();
        if (out<=0){
            System.out.println("输入有误");
        }else if(c.getBalance()-c.getAmount()>=out){
            c.withdraw(out);
        }else if (c.getBalance()-c.getAmount()+b.getBalance()>=out){
            double cMoney=c.getBalance()-c.getAmount();
            double bMoney=out-cMoney;
            c.withdraw(cMoney);
            b.withdraw(bMoney);
        }else{
            System.out.println("超出限额");
        }
        System.out.println("取款后:");
        for (int i = 0; i < card.length; i++) {
            System.out.println(card[i].getInfo());
        }
        System.out.println("输入存款金额:");
        double in=input.nextDouble();

        if (in<=0){
            System.out.println("金额有误");
        }else if(c.getAmount()>0){
            double cMoney=in-c.getAmount()>=0?c.getAmount():in;
            double bMoney=in-cMoney;
            c.save(cMoney);
            b.save(bMoney);
        }else{
            b.save(in);
        }
        System.out.println("存款后:");
        for(int i=0;i<card.length;i++){
            System.out.println(card[i].getInfo());
        }
    }
}
